<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>QSO</title>
<script type="text/javascript">

var dialog;

var myQuestionGrid;
var orderListGrid;
var currentQuestionGrid;
//加载正在处理中的问题
function loadCurrentQuestion(options){
	var o= options || {url:"${ctx}/qso/helpque/processing" };
	currentQuestionGrid.setOptions(o);
	currentQuestionGrid.loadData(false);//设置false,否则会再次发起请求
	
}
//加载我当前课程提的所有问题
function loadMyQuestion(options){
	var o= options || {url:"${ctx}/qso/helpque/myQuestion",parms: [{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}]};
	myQuestionGrid.setOptions(o);
   	myQuestionGrid.loadData(false);//设置false,否则会再次发起请求
}
//加载排队情况
function loadOrderList(){
	var o={url:"${ctx}/qso/helpque/orderList",parms: [{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}]};
	orderListGrid.setOptions(o);
	orderListGrid.loadData(false);//设置false,否则会再次发起请求
/*  	LG.ajax({
		url:"${ctx}/qso/helpque/orderList",
		success:function(result){
			orderListGrid.set({ data: result}); 
		}
	});  */
}

//提问之后回调
function askQuestionSuccess(){
	dialog.close();
	loadMyQuestion();
}

//点击 状态过滤
function checkMyQuestion(checkObj){
	var value="";
	if(checkObj.checked){
		value=checkObj.value;
		$("#myQuestionToolbar").find("input[name='checkMyQuestion']").each(function(index){
			if($(this).val()!=checkObj.value){
				$(this).attr("checked",false);
			}
		});
	}
	
    var options={
    		parms: [{ name: 'search_EQ_hpqStatus', value:value },{name:"sortName",value:"dateCre"},{name:"sortOrder",value:"desc"}],
    		url:"${ctx}/qso/helpque/myQuestion"
    };
    loadMyQuestion(options);

}

//撤销
function undoQuestion(){
    var data = myQuestionGrid.getCheckedRows();
    if (data.length == 0)
    	LG.tip('请选择行!');
    else
    {
        var checkedIds = [];
        $(data).each(function ()
        {
            checkedIds.push(this.hpqId);
        });
        $.ligerDialog.confirm('确定撤销 吗?', function (flag)
        {
        	if(flag){
                LG.ajax({
                	url:"${ctx}/qso/helpque/undoQuestion",
                    loading: '正在撤销中...',
                    data:{ids:checkedIds.join(',')},
                    success: function (result) {
                        LG.showSuccess(result.message);
                        loadMyQuestion();
                    },
                    error: function (result) {
                        LG.showError(result.message);
                    }
                });
        	}

        }); 
    }
}

function toolbarBtnItemClick(item) {
    switch (item.attr("toolbarid")) {
        case "askQuestion":
        	dialog=$.ligerDialog.open({url: '${ctx}/qso/helpque/view/add?hpqId=',height:450, width:650, showMax: true, showToggle: true, showMin: true, isResize: true, modal: true, title:"提问"});
            break;
        case "undoQuestion":
        	undoQuestion();
            break;
    }
}

$(function (){
	$("#mainbody").ligerLayout({ height: '100%', heightDiff: -3, leftWidth: 140,minLeftWidth: 120 });
	var bodyHeight = $(".l-layout-center:first").height();
	var tab=$("#questionTab").ligerTab({ 
		height: bodyHeight,
		onAfterSelectTabItem: function (tabid)
        {
        	if(tabid=="myQuestion"){
        		loadMyQuestion();
        	}else if(tabid=="orderList"){
        		loadOrderList();
        	}else if(tabid=="currentQuestion"){
        		loadCurrentQuestion();
        	}
    	}  
	}); 
	
    //预加载dialog的背景图片
    LG.prevDialogImage("${ctx}");

    $("#pageloading").hide();

    //正在解决的问题
    currentQuestionGrid = $("#currentQuestionGrid").ligerGrid({
        columns: [
        { display: '问题', name: 'hpqQuestion',width: 380, minWidth: 120},
        { display: '学生', name: 'stuName',width: 180, minWidth: 120},
        { display: '老师', name: 'teaName',width: 180, minWidth: 120},
        {name : 'groupId',hide: true},
        {
            display: '操作', isAllowHide: false,minWidth: 120,
            render: function (row)
            {
                return '<a href="javascript:void(0);" onclick="joinGroup(\'' + row.groupId + '\')">加入</a>';
            }
        }
        ], width: '100%', pkName: 'hpqId',height: '100%',checkbox : false,usePager:false
        
    });
    
    //我的提问
    myQuestionGrid = $("#myQuestionGrid").ligerGrid({
        columns: [
        { display: '问题', name: 'hpqQuestion',width: 350, minWidth: 120},
        { display: '时间', name: 'dateCre',width: 220, minWidth: 120},
        { display: '状态', name: 'hpqStatus',width: 220, minWidth: 120}
        ], width: '100%', pkName: 'hpqId',height: '100%',checkbox : true,usePager:false
        
    });
    
    //排队情况
    orderListGrid = $("#orderListGrid").ligerGrid({
        columns: [
        { display: '问题', name: 'hpqQuestion',width: 380, minWidth: 120},
        { display: '时间', name: 'dateCre',width: 170, minWidth: 120},
        { display: '状态', name: 'hpqStatus',width: 170, minWidth: 120},
        { display: '提问人', name: 'stuName',width: 170, minWidth: 120}
        ], width: '100%', pkName: 'hpqId',height: '100%',usePager:false
        
    });
    
	$(".l-toolbar-item").hover(
        	function (){
                	$(this).addClass("l-panel-btn-over");
            }, function (){
                	$(this).removeClass("l-panel-btn-over");
                	}
            );
        	
    $(".l-toolbar-item").click(function(){
			toolbarBtnItemClick($(this));
    });
    
    //初始化我的问题
	tab.selectTabItem("myQuestion");
        
});

function joinGroup(groupId){
	window.parent.initiativeJoin(groupId);
}

</script>

</head>
<body style="padding:5px">
	<div id="pageloading" style="display:block;"></div> 
	<div id="mainbody" class="l-mainbody" style="width:99.2%; margin:0 auto; margin-top:3px;" >
		<div id="questionTab" style="width:100%;height:100%; overflow: hidden; border: 1px solid #A3C0E8;">
			<div title="当前问题" lselected="true" style="height:100%;" tabid="currentQuestion">
				<div id="currentQuestionGrid" style="margin:1px; height:height:100%;">
					
				</div>
				
			</div>
			<div title="我的问题" tabid="myQuestion" id="myQuestionToolbar">
				<div class="l-panel-topbar l-toolbar" ligeruiid="ToolBar1000">
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon">
						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="WT"/>
						<span>等待</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
					</div>
					<div class="l-bar-separator"></div>
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon">
						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="CO"/>
						<span>完成</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
					</div>
					<div class="l-bar-separator"></div>
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon">
						<input type="checkbox" name="checkMyQuestion" onclick="checkMyQuestion(this)" value="DL"/>
						<span>拒绝</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
					</div>
					<div class="l-bar-separator"></div>
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="undoQuestion">
						<span>撤销</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
						<img src="${ctx}/static/icons/silkicons/delete.png">
					</div>
					<div class="l-bar-separator"></div>
					<div class="l-toolbar-item l-panel-btn l-toolbar-item-hasicon" toolbarid="askQuestion">
						<span>我要提问</span>
						<div class="l-panel-btn-l"></div>
						<div class="l-panel-btn-r"></div>
						<img src="${ctx}/static/icons/silkicons/add.png">
					</div>
				</div>
				<div id="myQuestionGrid" style="margin:1px; height:height:100%;">
					
				</div>
			</div>
			<div title="排队情况" tabid="orderList">
				<div id="orderListGrid" style="margin:1px; height:height:100%;">
					
				</div>
			</div>
		
		</div>
	</div>
</body>
</html>